package org.desktop.web.shared.domain.entities;

import java.io.Serializable;

import javax.persistence.*;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

import java.util.List;


/**
 * The persistent class for the FUNCTIONS database table.
 * 
 */
@Entity
@Table(name="FUNCTIONS")
@NamedQuery(name="Function.findAll", query="SELECT f FROM Function f")
@JsonAutoDetect(fieldVisibility=Visibility.ANY)
@JsonIgnoreProperties(value={"roles","subFunctions"})
@JsonInclude(Include.NON_NULL)
public class Function implements Serializable, com.google.gwt.user.client.rpc.IsSerializable {
	private static final long serialVersionUID = 1L;
	private int id;
	private String descFunction;
	private List<Role> roles;
	private List<SubFunction> subFunctions;

	public Function() {
	}


	@Id
	@Column(unique=true, nullable=false)
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}


	@Column(name="DESC_FUNCTION", nullable=false, length=100)
	public String getDescFunction() {
		return this.descFunction;
	}

	public void setDescFunction(String descFunction) {
		this.descFunction = descFunction;
	}


	//bi-directional many-to-many association to Role
	@ManyToMany
	@JoinTable(
		name="FUNCTIONS_ROLES"
		, joinColumns={
			@JoinColumn(name="ID_FUNCTION", nullable=false)
			}
		, inverseJoinColumns={
			@JoinColumn(name="ID_ROLE", nullable=false)
			}
		)
	public List<Role> getRoles() {
		return this.roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}


	//bi-directional many-to-one association to SubFunction
	@OneToMany(mappedBy="function")
	public List<SubFunction> getSubFunctions() {
		return this.subFunctions;
	}

	public void setSubFunctions(List<SubFunction> subFunctions) {
		this.subFunctions = subFunctions;
	}

	public SubFunction addSubFunction(SubFunction subFunction) {
		getSubFunctions().add(subFunction);
		subFunction.setFunction(this);

		return subFunction;
	}

	public SubFunction removeSubFunction(SubFunction subFunction) {
		getSubFunctions().remove(subFunction);
		subFunction.setFunction(null);

		return subFunction;
	}

}